package com.hejing.类的内部成员之四_代码块;

/**
 * ClassName: Person
 * Package: com.hejing.类的内部成员之四_代码块
 * Description:
 *
 * @Author: HeJing
 * @Create: 2023-03-28 18:51
 * @Version: 1.0
 */
public class Person {
    String name;
    int age;

    static String info;

    public void eat() {
        System.out.println("人吃饭");
    }

    public Person(){}

    // 非静态代码块:
    {
        System.out.println("非静态代码块1");
        name = "非静态属性赋值";
        age = 1;
    }

    // 代码块:
    static{
        System.out.println("静态代码块2");
        info = "静态属性调用";
    }

    // 重写toString方法
    public String toString() {
        return "Person{name: " + name + "\tage: " + age + "\tinfo: " + info + "}";
    }
}



















